package cn.kimoon.dau_android.API;

import cn.kimoon.dau_android.BuildConfig;
import cn.kimoon.dau_android.Utility.SPUtils;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xiangdong on 2016/11/30.
 */

public class AppClient {
    private static Retrofit mRetrofit = null;
    public static String mServerDomain = "dau.kimoon.cn";

    public static Retrofit retrofit() {
        if (mRetrofit == null) {
            OkHttpClient httpClient = new OkHttpClient();
            if (BuildConfig.DEBUG) {
                HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
                loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                httpClient = new OkHttpClient.Builder().addInterceptor(loggingInterceptor).build();
            }

            String baseUrl = "http://" + mServerDomain + "/";
            mRetrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .client(httpClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }

        return mRetrofit;
    }

    public static void clearRetrofit() {
        mRetrofit = null;
    }
}
